Skip to content

Add method to efficiently convert strings#415

Merged
ospfranco merged 4 commits into
mainfrom
oscar/jsi-efficient-string
Jun 12, 2026
Merged

Add method to efficiently convert strings#415
ospfranco merged 4 commits into
mainfrom
oscar/jsi-efficient-string

Conversation

@ospfranco

Copy link
Copy Markdown
Contributor

Adds a method to efficiently convert strings based on the work of @GrzywN specified here, performance gains on a simple test seem minor, but they might compound with larger string inputs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new helper for converting JSI strings to std::string and wires it into the native bindings, while also updating the example app/tooling (notably a React Native upgrade) and adjusting the example performance benchmark harness.

Changes:

  • Add jsi_string_to_utf8() (based on jsi::String::getStringData) and replace many .utf8(rt) call sites with it.
  • Update the example benchmark to populate more rows and run the benchmark automatically from the example app.
  • Upgrade React/React Native and related ecosystem/tooling (Metro/CLI/Hermes, CocoaPods/Gradle configs, lockfiles).

Reviewed changes

Copilot reviewed 15 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
yarn.lock Updates lockfile entries consistent with the dependency upgrades (React/React Native ecosystem).
package.json Bumps root dev dependencies (React/React Native).
example/src/performance_test.ts Changes benchmark setup (inserts many rows) and timing logic.
example/src/App.tsx Runs the performance test automatically after tests complete; displays timing.
example/package.json Updates example dependencies/tooling versions and modifies iOS helper scripts.
example/ios/Podfile.lock Reflects CocoaPods dependency changes from the RN/Hermes upgrade.
example/ios/OPSQLiteExample/Info.plist Uses Xcode build variables for versions; tweaks device/orientation settings.
example/ios/OPSQLiteExample.xcodeproj/project.pbxproj Adds flags/settings aligned with newer RN templates (e.g., legacy arch removal).
example/Gemfile.lock Updates Ruby dependencies (adds nkf, bumps bundler).
example/Gemfile Adds nkf.
example/android/gradle/wrapper/gradle-wrapper.properties Bumps Gradle wrapper version.
example/android/gradle.properties Adjusts Android build flags (Jetifier removal, edge-to-edge flag, etc.).
example/android/build.gradle Bumps Android SDK/build tools and Kotlin version.
example/android/app/src/main/kotlin/com/op/sqlite/example/MainApplication.kt Updates app init to newer RN entrypoint API.
cpp/utils.hpp Adds the new JSI string conversion helper implementation.
cpp/utils.cpp Switches variant/string conversions to use jsi_string_to_utf8().
cpp/OPSqlite.cpp Switches option string extraction to use jsi_string_to_utf8().
cpp/DBHostObject.cpp Switches multiple JSI string extractions to use jsi_string_to_utf8().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cpp/utils.hpp
Comment on lines +22 to +45
struct JSIStringDataAppender {
std::string *out;

void operator()(bool ascii, const void *data, size_t num) const {
if (ascii) {
out->append(static_cast<const char *>(data), num);
return;
}

const auto *u16 = static_cast<const char16_t *>(data);
out->reserve(out->size() + num);
for (size_t i = 0; i < num; i++) {
out->push_back(static_cast<char>(u16[i]));
}
}
};

inline std::string jsi_string_to_utf8(jsi::Runtime &rt,
const jsi::String &value) {
std::string result;
JSIStringDataAppender cb{&result};
value.getStringData(rt, cb);
return result;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As intended, JS effectively uses utf-8 but the retarded decision at the beginning of the universe was to use utf-16

Comment thread example/src/performance_test.ts
Comment thread example/src/App.tsx
Comment thread package.json
Comment thread example/src/App.tsx
Comment thread example/package.json
@ospfranco ospfranco merged commit 170ecbf into main Jun 12, 2026
10 checks passed
@ospfranco ospfranco deleted the oscar/jsi-efficient-string branch June 12, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants